<?php
    use User\Model\LotteryModel;
?>
<link href="/Public/css/common/switchery.css" rel="stylesheet"/>
<style>
    .next-step{position:absolute;right:50px;top:10px;}
    .nav-tabs li.active{border-bottom:3px solid blue}
    .panel-body{min-height:800px;}
    .step1-tab{width:240px;height:40px;z-index:1;list-style:none;background-color:#f5f5f5;padding:0}
    .step1-tab li{width:50%;height:40px;float:left;padding:10px 10px;text-align:center;cursor:pointer}
    .step1-tab li.active {background-color:#3896DC;}
    .step1-tab li a{padding:10px 22px;text-decoration:none}
    .step1-tab li.active a{color:#fff}

    .preview-tab{width:320px;height:40px;position:absolute;right:100px;z-index:1;list-style:none;
        background-color:#f5f5f5;padding:0;}
    .preview-tab li{width:33%;height:40px;float:left;padding:10px 10px;text-align:center;cursor:pointer}
    .preview-tab li.active{background-color:#3896DC;color:#fff}
    .preview{position:absolute;top:200px;right:100px;z-index:1}
    .preview-top{width:320px;height:64px;background-image:url('/Public/images/wx_top.png')}
    .preview-frame{width:320px;height:480px;border:1px solid #ccc;text-align:center;z-index:1;
        background-image:url({$lottery['img-background']});background-size:cover;background-repeat:no-repeat}
    .preview-result1{display:block}
    .img-background{float:right;margin-right:10px;margin-top:10px;width:80px;height:30px;border:1px dashed #ccc;
        cursor:pointer;color:white;background-color:#56A1E3;font-size:14px;line-height:30px}
    .img-turntable{width:300px;height:385px;margin-top:10px;margin-left:10px;background-repeat:no-repeat;
        background-image:url('/Public/images/lottery/pre-table.png');background-size:cover}
    .img-rule{width:130px;height:80px;margin-left:10px;float:left;
        background-image:url('/Public/images/lottery/pre-frame.png');background-repeat:no-repeat;background-size:cover}
    .img-rule img{position:absolute;left:15px;bottom:30px;width:100px;height:70px;padding:5px}
    .img-info{width:130px;height:80px;margin-right:10px;float:right;
        background-image:url('/Public/images/lottery/pre-frame.png');background-repeat:no-repeat;background-size:cover}
    .img-info img{position:absolute;right:18px;bottom:30px;width:100px;height:70px;padding:5px}
    .preview-result2,.preview-result3{display:none}
    .img-result{width:200px;height:400px;margin-top:20px;color:red}
    .img-result-frame{width:250px;height:350px;position:absolute;top:100px;left:35px;opacity: 0.5}
    .img-result-side{width:250px;height:350px;position:absolute;top:100px;left:35px;padding:5px;}
    .img-gift-side{width:180px;height:180px;position:absolute;top:120px;left:60px;}
    .img-gift{width:60px;height:70px;position:absolute;top:170px;left:120px;}
    .img-sun{width:30px;height:30px;position:absolute;top:140px;right:110px;}
    .img-thunder{width:100px;height:60px;position:absolute;top:150px;left:100px;}
    .img-shake{width:150px;height:130px;position:absolute;top:150px;left:75px;}
    .img_custom,.img_custom2{position:absolute;right:20px;top:140px;width:80px;height:100px}
    .img_accept{position:absolute;left:40px;bottom:100px;width:130px;height:100px}
    .img_again{position:absolute;left:40px;bottom:100px;width:130px;height:110px}
    .img_share,.img_share2{position:absolute;right:40px;bottom:120px;width:100px;height:50px}
    .img-edit{width:45px;height:30px;border:1px dashed #ccc;cursor:pointer;color:white;background-color:#56A1E3;
        font-size:14px;line-height:30px;position:absolute}
    .img-custom,.img-custom2{top:110px;right:45px}
    .img-share,.img-share2{bottom:190px;right:50px;}
    .img-accept{bottom:190px;left:50px;}
    .img-again{bottom:190px;left:50px;}

    .modal-footer{text-align:left}
    .tools{margin: -20px -5px;}
    .tools a{background: white;border-radius: 3px;-webkit-border-radius: 3px;color: #858582;float: left;
        margin-left: 10px;padding: 10px;text-decoration: none;}
    .tools a:first-child{background-image: url('/Public/images/minus.png');background-repeat:no-repeat;
        background-position: 50% center;}
    .tools a:nth-child(2){margin-right: 20px;background-image: url('/Public/images/plus-small.png');
        background-repeat:no-repeat;background-position: 50% center}

</style>
<div class="row">
    <div class="col-lg-12">
        <form role="form" class="form-horizontal" action="/User/Lottery/update" method="post" enctype="multipart/form-data">
            <input type="hidden" name="id" value="{$id}">
            <section class="panel step1">
                <header class="panel-heading">
                    <if condition="$id eq -1">新建<else/>{$lottery["title"]} - 编辑</if>
                    <a class="btn btn-info next-step" href="javascript:;" onclick="step1()">下一步</a>
                </header>
                <header class="panel-heading" style="border-bottom:0">
                    <ul class="step1-tab" id="myTab">
                        <li class="active"><a href="#basic">基础设置</a></li>
                        <li><a href="#award">抽奖设置</a></li>
                    </ul>
                </header>
                <div class="panel-body">
                    <div class="form-horizontal tab-content">
                        <ul class="preview-tab">
                            <li class="active">首页</li>
                            <li>中奖页面</li>
                            <li>未中奖页面</li>
                        </ul>
                        <div class="preview">
                            <div class="preview-top"></div>
                            <div class="preview-frame preview-result1">
                                <div class="img-background">编辑背景</div>
                                <div class="img-turntable"></div>
                                <div class="img-rule"><img src="/Public/images/lottery/pre-rule.png"></div>
                                <div class="img-info"><img src="/Public/images/lottery/pre-info.png"></div>
                            </div>
                            <div class="preview-frame preview-result2">
                                <div class="img-result">
                                    <img class="img-result-frame" src="/Public/images/lottery/pre-result.png">
                                    <img class="img-result-side" src="/Public/images/lottery/pre-result-side.png">
                                    <img class="img-gift-side" src="/Public/images/lottery/pre-gift-side.png">
                                    <img class="img-gift" src="/Public/images/lottery/pre-gift.png">
                                    <img class="img-sun" src="/Public/images/lottery/pre-sun.png">
                                    <img class="img_custom" src="{$lottery['img-custom']}"><span class="img-edit img-custom">编辑</span>
                                    <img class="img_accept" src="{$lottery['img-accept']}"><span class="img-edit img-accept">编辑</span>
                                    <img class="img_share" src="{$lottery['img-share']}"><span class="img-edit img-share">编辑</span>
                                </div>
                            </div>
                            <div class="preview-frame preview-result3">
                                <div class="img-result">
                                    <img class="img-result-frame" src="/Public/images/lottery/pre-result.png">
                                    <img class="img-result-side" src="/Public/images/lottery/pre-result-side.png">
                                    <img class="img-thunder" src="/Public/images/lottery/pre-thunder.png">
                                    <img class="img-shake" src="/Public/images/lottery/pre-shake.png">
                                    <img class="img_custom2" src="{$lottery['img-custom']}"><span class="img-edit img-custom2">编辑</span>
                                    <img class="img_again" src="{$lottery['img-again']}"><span class="img-edit img-again">编辑</span>
                                    <img class="img_share2" src="{$lottery['img-share']}"><span class="img-edit img-share2">编辑</span>
                                </div>
                            </div>
                        </div>
                        <div class="tab-pane active" id="basic">
                            <div class="form-group">
                                <label class="col-sm-2 col-sm-2 control-label"><span style="color:red">*</span>活动名称</label>
                                <div class="col-lg-4">
                                    <input type="text" class="form-control required" title="活动名称" name="title" value="{$lottery['title']}">
                                </div>
                            </div>

                            <div class="form-group">
                                <label class="col-sm-2 col-sm-2 control-label"><span style="color:red">*</span>活动时间</label>
                                <div class="col-lg-2">
                                    <input type="text" class="form-control required" title="活动时间" style="width:350px;" id="date-picker1" name="range_date" value="{$lottery['range_date']}">
                                </div>
                            </div>

                            <div class="form-group">
                                <div class="col-sm-2 col-sm-2 control-label">活动规则</div>
                                <div class="col-lg-4">
                                    <textarea id="editor-container" name="info" style="width:450px;height:300px"></textarea>
                                </div>
                            </div>

                            <div class="form-group">
                                <label class="col-lg-2 col-sm-2 control-label">强制关注</label>
                                <div class="col-lg-6">
                                    <input type="checkbox" name="force_follow" class="js-switch" <if condition="$lottery['force_follow'] eq LotteryModel::FOLLOW_YES">checked</if>/>
                                </div>
                            </div>

                            <div class="form-group upload-force-img" <if condition="$lottery['force_follow'] eq LotteryModel::FOLLOW_NO">style="display:none"</if>>
                                <label class="col-lg-2 col-sm-2 control-label">强制关注二维码</label>
                                <div class="col-lg-6">
                                    <img src="{$lottery['force_image']}" width="100px" height="100px">
                                    <input type="file" onchange="uploadImage(this, '', ['jpg', 'jpeg', 'png', 'gif'], [500, 500], 200);" accept="image/gif,image/jpeg,image/jpg,image/png">
                                    <input type="hidden" name="force_image" value="{$lottery['force_image']}">
                                    <p class="help-block">有默认的关注二维码图片，可自定义替换，尺寸不得超过500px*500px，格式支持jpg、jpeg、png、gif，大小不得超过200k</p>
                                </div>
                            </div>

                            <div class="form-group">
                                <label class="col-lg-2 col-sm-2 control-label">禁止分享</label>
                                <div class="col-lg-6">
                                    <input type="checkbox" name="share_able" class="js-switch" <if condition="$lottery['share_able'] eq LotteryModel::FOLLOW_YES">checked</if>/>
                                </div>
                            </div>
                        </div>

                        <div class="tab-pane" id="award">
                            <div class="form-group">
                                <label class="col-sm-2 col-sm-2 control-label"><span style="color:red">*</span>每日游戏次数上限</label>
                                <div class="col-lg-4">
                                    <input type="text" class="form-control required" title="每日游戏次数上限" name="number_limits" value="{$lottery['number_limits']}">
                                    <p class="help-block">如若忽略，请填-1</p>
                                </div>
                            </div>

                            <div class="form-group">
                                <label class="col-sm-2 col-sm-2 control-label"><span style="color:red">*</span>每人每日游戏次数上限</label>
                                <div class="col-lg-4">
                                    <input type="text" class="form-control required" title="每人每日游戏次数上限" name="per_num" value="{$lottery['per_num']}">
                                    <p class="help-block">默认1次</p>
                                </div>
                            </div>

                            <div class="form-group">
                                <label class="col-sm-2 col-sm-2 control-label">分享奖励次数</label>
                                <div class="col-lg-4">
                                    <input type="text" class="form-control" name="share_play" value="{$lottery['share_play']}">
                                    <p class="help-block">默认0次</p>
                                </div>
                            </div>

                            <div class="form-group">
                                <label class="col-sm-2 col-sm-2 control-label"><span style="color:red">*</span>每日中奖次数上限</label>
                                <div class="col-lg-4">
                                    <input type="text" class="form-control required" title="每日中奖次数上限" name="day_limit" value="{$lottery['day_limit']}">
                                    <p class="help-block">如若忽略，请填-1</p>
                                </div>
                            </div>

                            <div class="form-group">
                                <label class="col-sm-2 col-sm-2 control-label"><span style="color:red">*</span>每人中奖次数</label>
                                <div class="col-lg-4">
                                    <input type="text" class="form-control required" title="每人中奖次数" name="per_num_sum" value="{$lottery['per_num_sum']}">
                                    <p class="help-block">默认1次</p>
                                </div>
                            </div>

                            <div class="form-group">
                                <label class="col-sm-2 col-sm-2 control-label"><span style="color:red">*</span>总中奖率</label>
                                <div class="col-lg-4">
                                    <input type="text" class="form-control required" title="总中奖率" name="total_rate" value="{$lottery['total_rate']}">
                                    <p class="help-block">(取值范围0.00001-100.00000)</p>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </section>

            <section class="panel step2" style="display:none">
                <header class="panel-heading">
                    <if condition="$id eq -1">奖项设置<else/>{$lottery["title"]} - 奖项设置</if>
                    <a class="btn btn-info next-step" href="javascript:;" onclick="step2()">下一步</a>
                </header>
                <header class="panel-heading custom-tab">
                    <ul class="nav nav-tabs" id="award_tab">
                        <li class="active">
                            <a href="#award1" data-item="{$f}" data-toggle="tab">奖项1</a>
                        </li>
                        <volist name="lottery_items" id="item" offset="1">
                            <li>
                                <a href="#award{$i+1}" data-item="{$item['id']}" data-toggle="tab">奖项{$i+1}</a>
                            </li>
                        </volist>
                    </ul>
                    <empty name="lottery_items">
                        <input type="hidden" name="award_num" value="1">
                    <else/>
                        <input type="hidden" name="award_num" value="{$lottery_items|count}">
                    </empty>
                    <span class="tools pull-right">
                        <a class="" href="javascript:;" onclick="deleteAward();"></a>
                        <a class="" href="javascript:;" onclick="addAward();"></a>
                    </span>
                </header>
                <div class="panel-body form-horizontal">
                    <div class="tab-content" id="award_content">
                        <div class="tab-pane active" id="award1">
                            <input type="hidden" name="item_id1" value="{$f}">
                            <div class="form-group">
                                <label class="col-xs-12 col-sm-3 col-md-2 control-label"><span style="color:red">*</span> 奖项等级</label>
                                <div class="col-sm-6 col-xs-12">
                                    <div class="form-control-static">
                                        <select name="level1" class="form-control">
                                            <volist name="levels" id="level">
                                                <option value="{$i}" <if condition="$i eq $lottery_items[0]['level']">selected</if>>{$level}</option>
                                            </volist>
                                        </select>
                                    </div>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-lg-2 col-sm-2 control-label"><span style="color:red">*</span> 奖项名称</label>
                                <div class="col-lg-6">
                                    <empty name="lottery_items">
                                        <input class="form-control valid" title="奖项名称" name="name1">
                                    <else />
                                        <volist name="lottery_items" id="item" offset="0" length="1">
                                            <input class="form-control valid" title="奖项名称" name="name1" value="{$item['name']}">
                                        </volist>
                                    </empty>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-lg-2 col-sm-2 control-label"><span style="color:red">*</span> 奖项数量</label>
                                <div class="col-lg-6">
                                    <empty name="lottery_items">
                                        <input class="form-control valid" title="奖项数量" name="number1">
                                    <else />
                                        <volist name="lottery_items" id="item" offset="0" length="1">
                                            <input class="form-control valid" title="奖项数量" name="number1" value="{$item['number']}">
                                        </volist>
                                    </empty>
                                </div>
                            </div>
                            <!--<div class="form-group">-->
                                <!--<label class="col-lg-2 col-sm-2 control-label"><span style="color:red">*</span> 奖项图片</label>-->
                                <!--<div class="col-lg-6">-->
                                    <!--<empty name="lottery_items">-->
                                        <!--<img src="" class="thumbnail" title="奖项图片" width="100px" height="100px" data-preview="uploadFile1">-->
                                        <!--<input name="pic1" type="file" data-action="uploadFile1">-->
                                    <!--<else />-->
                                        <!--<volist name="lottery_items" id="item" offset="0" length="1">-->
                                            <!--<if condition="$item['pic'] eq null">-->
                                                <!--<img src="" class="thumbnail" title="奖项图片" width="100px" height="100px" data-preview="uploadFile1">-->
                                            <!--<else/>-->
                                                <!--<img src="{$item['pic']}" class="thumbnail" title="奖项图片" width="100px" height="100px" data-preview="uploadFile1">-->
                                            <!--</if>-->
                                            <!--<input type="hidden" name="pic1" value="{$item['pic']}" data-set="uploadFile1">-->
                                            <!--<input type="file" class="changePic" data-action="uploadFile1">-->
                                        <!--</volist>-->
                                    <!--</empty>-->
                                <!--</div>-->
                            <!--</div>-->
                        </div>
                        <volist name="lottery_items" id="item" offset="1" key="k">
                            <div class="tab-pane" id="award{$k+1}">
                                <input type="hidden" name="item_id{$k+1}" value="{$item['id']}">
                                <div class="form-group">
                                    <label class="col-xs-12 col-sm-3 col-md-2 control-label"><span style="color:red">*</span> 奖项等级</label>
                                    <div class="col-sm-6 col-xs-12">
                                        <div class="form-control-static">
                                            <select name="level{$k+1}" class="form-control">
                                                <volist name="levels" key="key_level" id="level">
                                                    <option value="{$key_level}" <if condition="$key_level eq $item['level']">selected</if>>{$level}</option>
                                                </volist>
                                            </select>
                                        </div>
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label class="col-lg-2 col-sm-2 control-label"><span style="color:red">*</span> 奖项名称</label>
                                    <div class="col-lg-6">
                                        <input class="form-control valid" title="奖项名称" name="name{$k+1}" value="{$item['name']}">
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label class="col-lg-2 col-sm-2 control-label"><span style="color:red">*</span> 奖项数量</label>
                                    <div class="col-lg-6">
                                        <input class="form-control valid" title="奖项数量" name="number{$k+1}" value="{$item['number']}">
                                    </div>
                                </div>
                                <!--<div class="form-group">-->
                                    <!--<label class="col-lg-2 col-sm-2 control-label"><span style="color:red">*</span> 奖项图片</label>-->
                                    <!--<div class="col-lg-6">-->
                                        <!--<if condition="$item['pic'] eq null">-->
                                            <!--<img src="" class="thumbnail" title="奖项图片" width="100px" height="100px" data-preview="uploadFile{$k+1}">-->
                                        <!--<else/>-->
                                            <!--<img src="{$item['pic']}" class="thumbnail" title="奖项图片" width="100px" height="100px" data-preview="uploadFile{$k+1}">-->
                                        <!--</if>-->
                                        <!--<input type="hidden" name="pic{$k+1}" value="{$item['pic']}" data-set="uploadFile{$k+1}">-->
                                        <!--<input type="file" class="changePic" data-action="uploadFile{$k+1}">-->
                                    <!--</div>-->
                                <!--</div>-->
                            </div>
                        </volist>
                    </div>
                </div>
            </section>

            <section class="panel step3" style="display:none">
                <header class="panel-heading">
                    <if condition="$id eq -1">分享设置<else/>{$lottery["title"]} - 分享设置</if>
                    <button class="btn btn-info next-step" type="submit" href="javascript:;">保存</button>
                </header>
                <div class="panel-body">
                    <div class="form-horizontal">
                        <div class="form-group">
                            <label class="col-sm-2 col-sm-2 control-label">分享标题</label>
                            <div class="col-lg-4">
                                <input type="text" class="form-control" name="share_title" value="{$lottery['share_title']}">
                            </div>
                        </div>

                        <div class="form-group">
                            <div class="col-sm-2 col-sm-2 control-label">分享描述</div>
                            <div class="col-lg-4">
                                <textarea name="share_desc" style="width:450px;height:150px">{$lottery["share_desc"]}</textarea>
                            </div>
                        </div>

                        <div class="form-group">
                            <label class="col-sm-2 col-sm-2 control-label">分享链接</label>
                            <div class="col-lg-4">
                                <input type="text" class="form-control" name="share_link" value="{$lottery['share_link']}">
                                <p class="help-block">默认为首页的链接</p>
                            </div>
                        </div>

                        <div class="form-group">
                            <label class="col-lg-2 col-sm-2 control-label">分享图标</label>
                            <div class="col-lg-6">
                                <img src="{$lottery['share_img']}" width="100px" height="100px">
                                <input type="file" onchange="uploadImage(this, '', ['jpg', 'jpeg', 'png', 'gif'], [2000, 2000], 200);" accept="image/gif,image/jpeg,image/jpg,image/png">
                                <input type="hidden" name="share_img" value="{$lottery['share_img']}">
                                <p class="help-block">有默认的分享图标，可自定义替换，尺寸不得超过100px*100px，格式支持jpg、jpeg、png、gif，大小不得超过200k</p>
                            </div>
                        </div>
                    </div>
                </div>
            </section>
            <div aria-hidden="true" aria-labelledby="myModalLabel" role="dialog" tabindex="-1" id="img-background" class="modal fade">
                <div class="modal-dialog">
                    <div class="modal-content">
                        <div class="modal-header">
                            <button aria-hidden="true" data-dismiss="modal" class="close" type="button">×</button>
                            <h4 class="modal-title">背景</h4>
                        </div>
                        <div class="modal-body">
                            <img src="{$lottery['img-background']}" width="100px" height="100px">
                            <input type="file" onchange="uploadImage(this, 'preview-frame', ['jpg', 'jpeg', 'png', 'gif'], [800, 1500], 800);" accept="image/gif,image/jpeg,image/jpg,image/png">
                            <input type="hidden" name="img-background" value="{$lottery['img-background']}">
                            <p class="help-block">有默认的背景图片，可自定义替换，尺寸不得超过800px*1500px，格式支持jpg、jpeg、png、gif，大小不得超过800k</p>
                        </div>
                        <div class="modal-footer"></div>
                    </div>
                </div>
            </div>
            <div aria-hidden="true" aria-labelledby="myModalLabel" role="dialog" tabindex="-1" id="img-accept" class="modal fade">
                <div class="modal-dialog">
                    <div class="modal-content">
                        <div class="modal-header">
                            <button aria-hidden="true" data-dismiss="modal" class="close" type="button">×</button>
                            <h4 class="modal-title">去领奖</h4>
                        </div>
                        <div class="modal-body">
                            <img src="{$lottery['img-accept']}" width="100px" height="100px">
                            <input type="file" onchange="uploadImage(this, 'img_accept', ['jpg', 'jpeg', 'png', 'gif'], [260, 250], 200);" accept="image/gif,image/jpeg,image/jpg,image/png">
                            <input type="hidden" name="img-accept" value="{$lottery['img-accept']}">
                            <p class="help-block">有默认的按钮图片，可自定义替换，尺寸不得超过260px*250px，格式支持jpg、jpeg、png、gif，大小不得超过200k</p>
                        </div>
                        <div class="modal-footer"></div>
                    </div>
                </div>
            </div>
            <div aria-hidden="true" aria-labelledby="myModalLabel" role="dialog" tabindex="-1" id="img-share" class="modal fade">
                <div class="modal-dialog">
                    <div class="modal-content">
                        <div class="modal-header">
                            <button aria-hidden="true" data-dismiss="modal" class="close" type="button">×</button>
                            <h4 class="modal-title">分享</h4>
                        </div>
                        <div class="modal-body">
                            <img src="{$lottery['img-share']}" width="100px" height="100px">
                            <input type="file" onchange="uploadImage(this, 'img_share', ['jpg', 'jpeg', 'png', 'gif'], [250, 250], 200);" accept="image/gif,image/jpeg,image/jpg,image/png">
                            <input type="hidden" name="img-share" value="{$lottery['img-share']}">
                            <p class="help-block">有默认的按钮图片，可自定义替换，尺寸不得超过250px*250px，格式支持jpg、jpeg、png、gif，大小不得超过200k</p>
                        </div>
                        <div class="modal-footer"></div>
                    </div>
                </div>
            </div>
            <div aria-hidden="true" aria-labelledby="myModalLabel" role="dialog" tabindex="-1" id="img-custom" class="modal fade">
                <div class="modal-dialog">
                    <div class="modal-content">
                        <div class="modal-header">
                            <button aria-hidden="true" data-dismiss="modal" class="close" type="button">×</button>
                            <h4 class="modal-title">自定义按钮：跳转链接/关注我们</h4>
                        </div>
                        <div class="modal-body">
                            <div class="form-horizontal">
                                <div class="form-group">
                                    <label class="col-lg-3 col-sm-2 control-label">按钮图片</label>
                                    <div class="col-lg-8">
                                        <img src="{$lottery['img-custom']}" width="100px" height="100px">
                                        <input type="file" onchange="uploadImage(this, 'img_custom', ['jpg', 'jpeg', 'png', 'gif'], [150, 250], 200);" accept="image/gif,image/jpeg,image/jpg,image/png">
                                        <input type="hidden" name="img-custom" value="{$lottery['img-custom']}">
                                        <p class="help-block">有默认的按钮图片，可自定义替换，尺寸不得超过150px*250px，格式支持jpg、jpeg、png、gif，大小不得超过200k</p>
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label class="col-lg-3 col-sm-2 control-label">按钮动作</label>
                                    <div class="col-lg-8">
                                        <label class="radio-inline">
                                            <input type="radio" name="custom-choose" onclick="$('.custom-code').show();$('.custom-link').hide()" <if condition="$lottery['custom-choose'] eq LotteryModel::CUSTOM_CODE">checked="checked"</if> value="<?php echo LotteryModel::CUSTOM_CODE; ?>">关注二维码
                                        </label>
                                        <label class="radio-inline">
                                            <input type="radio" name="custom-choose" onclick="$('.custom-code').hide();$('.custom-link').show()" <if condition="$lottery['custom-choose'] eq LotteryModel::CUSTOM_LINK">checked="checked"</if> value="<?php echo LotteryModel::CUSTOM_LINK; ?>">跳转地址
                                        </label>
                                    </div>
                                </div>
                                <div class="form-group custom-code" <if condition="$lottery['custom-choose'] eq LotteryModel::CUSTOM_LINK">style="display:none"</if>>
                                    <label class="col-lg-3 col-sm-2 control-label">关注二维码</label>
                                    <div class="col-lg-8">
                                        <img src="{$lottery['img-code']}" width="100px" height="100px">
                                        <input type="file" onchange="uploadImage(this, '', ['jpg', 'jpeg', 'png', 'gif'], [500, 500], 200);" accept="image/gif,image/jpeg,image/jpg,image/png">
                                        <input type="hidden" name="img-code" value="{$lottery['img-code']}">
                                        <p class="help-block">有默认的关注二维码图片，可自定义替换，尺寸不得超过500px*500px，格式支持jpg、jpeg、png、gif，大小不得超过200k</p>
                                    </div>
                                </div>
                                <div class="form-group custom-link" <if condition="$lottery['custom-choose'] eq LotteryModel::CUSTOM_CODE">style="display:none"</if>>
                                    <label class="col-lg-3 col-sm-2 control-label">链接地址</label>
                                    <div class="col-lg-8">
                                        <input class="form-control" name="custom-link" value="{$lottery['custom-link']}">
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <div aria-hidden="true" aria-labelledby="myModalLabel" role="dialog" tabindex="-1" id="img-again" class="modal fade">
                <div class="modal-dialog">
                    <div class="modal-content">
                        <div class="modal-header">
                            <button aria-hidden="true" data-dismiss="modal" class="close" type="button">×</button>
                            <h4 class="modal-title">再玩一次</h4>
                        </div>
                        <div class="modal-body">
                            <img src="{$lottery['img-again']}" width="100px" height="100px">
                            <input type="file" onchange="uploadImage(this, 'img_again', ['jpg', 'jpeg', 'png', 'gif'], [250, 250], 200);" accept="image/gif,image/jpeg,image/jpg,image/png">
                            <input type="hidden" name="img-again" value="{$lottery['img-again']}">
                            <p class="help-block">有默认的按钮图片，可自定义替换，尺寸不得超过250px*250px，格式支持jpg、jpeg、png、gif，大小不得超过200k</p>
                        </div>
                        <div class="modal-footer"></div>
                    </div>
                </div>
            </div>
        </form>
    </div>
</div>

<script type="text/javascript" charset="utf-8" src="/Public/js/common/ueditor.config.js"></script>
<script type="text/javascript" charset="utf-8" src="/Public/js/common/ueditor.all.min.js"></script>
<script type="text/javascript" charset="utf-8" src="/Public/js/common/lang/zh-cn/zh-cn.js"></script>
<script type="text/javascript" src="/Public/js/laydatenew/laydate.js"></script>
<script type="text/javascript" src="/Public/js/common.upload.js"></script>

<script type="text/javascript" src="/Public/js/common/switchery.js"></script>
<script type="text/javascript" src="/Public/js/common/ios-init.js"></script>
<script type="text/javascript">
    $('.preview-tab li').click(function(){
        $('.preview-tab li').removeClass('active');
        $(this).addClass('active');
        $('.preview-frame').hide();
        var index = $(this).index() + 1;
        $('.preview-result'+index).show();
    });

    $('#myTab a:first').tab('show');//初始化显示哪个tab

    $('#myTab a').click(function (e) {
        e.preventDefault();//阻止a链接的跳转行为
        $(this).tab('show');//显示当前选中的链接及关联的content
    });

    common.upload.img.init();
    laydate.render({
        elem: '#date-picker1',
        type: 'datetime',
        range: '~',
        format: 'yyyy-MM-dd HH:mm:ss',
        value: '{$lottery["range_date"]}',
        trigger: 'click'
    });

    var editor = UE.getEditor('editor-container');
    var content = '<?php if(empty($lottery["info"])){echo "";}else{ echo $lottery["info"];}?>';
    editor.addListener("ready", function () {
        editor.setContent(content);
    });

    $("input[name=force_follow]").on("change", function(){
        $(".upload-force-img").toggle();
    });

    $('.img-background').click(function(){$('#img-background').modal('show')});
    $('.img-accept').click(function(){$('#img-accept').modal('show')});
    $('.img-share,.img-share2').click(function(){$('#img-share').modal('show')});
    $('.img-custom,.img-custom2').click(function(){$('#img-custom').modal('show')});
    $('.img-again').click(function(){$('#img-again').modal('show')});

    function step1(){
        var ret = true;
        $(".required").each(function(){
            if($(this).val() === ""){
                alert("请添加"+$(this).attr("title"));
                ret = false;
                return false;
            }
        });
        if(ret){
            $('.step1').hide();
            $('.step2').show();
        }
    }

    function step2(){
        var ret = true;
        $(".valid").each(function(){
            if($(this).val() === ""){
                alert("请添加"+$(this).attr("title"));
                ret = false;
                return false;
            }
        });
        if(ret){
            $('.step2').hide();
            $('.step3').show();
        }
    }
    function uploadImage(c, cls, types, size, kb){
        var file = c.files[0];
        var _this = $(c);
        var filepath = _this.val();
        //格式判断
        var extStart = filepath.lastIndexOf(".") + 1;
        var ext = filepath.substring(extStart, filepath.length).toLowerCase();
        if (types.indexOf(ext) === -1) {
            alert("仅支持上传"+types+"格式的图片");
            return false;
        }
        //大小判断
        var num = file.size / 1024;
        num = parseInt(num.toFixed(0));
        if(num > kb){
            alert("上传的图片大小不能超过"+kb+"KB！");
            return false;
        }
        var reader = new FileReader();
        reader.readAsDataURL(file);
        reader.onload = function (e) {
            var image = new Image();
            image.src= e.target.result;
            image.onload = function(){
                //宽高判断
                var image = new Image();
                image.src= e.target.result;
                if(image.width > size[0] || image.height > size[1]){
                    alert("上传的图片宽度不能超过"+size[0]+"px, 高度不能超过"+size[1]+"px");
                }else{
                    $.ajax({
                        url: "/User/Lottery/uploadFile",
                        type: "post",
                        dataType: 'json',
                        data: {img: e.target.result},
                        success:function(result){
                            console.log(result.msg);
                            if(result['code'] === 0){
                                _this.prev().attr("src",result.msg);
                                _this.next().attr("value",result.msg);
                                if(cls === 'preview-frame'){
                                    $('.'+cls).css('background-image', 'url('+result.msg+')');
                                }else if(cls !== ''){
                                    $('.'+cls).attr('src', result.msg);
                                    $('.'+cls+'2').attr('src', result.msg);
                                }else{}
                            }
                        }
                    });
                }
            };
        };
    }

    //增加奖项
    function addAward(){
        var award_num = parseInt($("#award_tab li").length) + 1;
        var lottery_id = $('input[name=id]').val();
        var data = <?php echo json_encode($levels);?>;
        var level_html = '';
        if(award_num <= 5){
            $("input[name=award_num]").val(award_num);
            $("#award_tab li").removeClass('active');
            $("#award_tab").append('<li class="active"><a href="#award'+award_num+'" data-item="" data-toggle="tab">奖项'+award_num+'</a></li>');
            $("#award_content .tab-pane").removeClass('active');
            for(var i in data){
                var d = data[i];
                level_html += "<option value='"+i+"'>"+d+"</option>";
            }
            $("#award_content").append('<div class="tab-pane active" id="award'+award_num+'">'+
                '<input type="hidden" name="item_id'+award_num+'" value="">'+
                '<div class="form-group">'+
                    '<label class="col-xs-12 col-sm-3 col-md-2 control-label"><span style="color:red">*</span> 奖项等级</label>'+
                    '<div class="col-sm-6 col-xs-12">'+
                        '<div class="form-control-static">'+
                            '<select name="level'+award_num+'" class="form-control">'+level_html+''+

                            '</select>'+
                        '</div>'+
                    '</div>'+
                '</div>'+
                '<div class="form-group">'+
                    '<label class="col-lg-2 col-sm-2 control-label"><span style="color:red">*</span> 奖项名称</label>'+
                    '<div class="col-lg-6">'+
                        '<input class="form-control valid" title="奖项名称" name="name'+award_num+'">'+
                    '</div>'+
                '</div>'+
                '<div class="form-group">'+
                    '<label class="col-lg-2 col-sm-2 control-label"><span style="color:red">*</span> 奖项数量</label>'+
                    '<div class="col-lg-6">'+
                        '<input class="form-control valid" title="奖项数量" name="number'+award_num+'">'+
                    '</div>'+
                '</div>'+
                // '<div class="form-group">'+
                //     '<label class="col-lg-2 col-sm-2 control-label"><span style="color:red">*</span> 奖项图片</label>'+
                //     '<div class="col-lg-6">'+
                //         '<img src="" class="thumbnail" title="奖项图片" width="100px" height="100px" data-preview="uploadFile'+award_num+'">'+
                //         '<input name="pic'+award_num+'" type="file" data-action="uploadFile'+award_num+'">'+
                //     '</div>'+
                // '</div></div>');
                '</div>');
            //上传图片
            common.upload.img.init();
        }else{
            alert('最多添加5个奖项！');
        }
    }

    //减少奖项
    function deleteAward(){
        if(!confirm('确认删除该奖项吗？')) return false;
        var award_num = parseInt($("#award_tab li").length);
        var lottery_id = $('input[name=id]').val();
        if(award_num>1){
            //编辑时ajax删除奖项表一条记录，新增时不用
            if(lottery_id != -1){        //编辑大转盘
                var item_id = $('#award_tab .active a').attr('data-item');
                if(item_id){
                    $.ajax({
                        data: {id: item_id},
                        dataType: 'json',
                        url: '/User/Lottery/deleteAward',
                        type: 'get',
                        success: function (res) {}
                    });
                }
                $("input[name=award_num]").val(award_num-1);
                $("#award_tab .active").remove();
                $("#award_tab li:last").addClass('active');
                $("#award_content .tab-pane.active").remove();
                $("#award_content .tab-pane:last").addClass('active');
            }else{      //新增大转盘
                $("input[name=award_num]").val(award_num-1);
                $("#award_tab .active").remove();
                $("#award_tab li:last").addClass('active');
                $("#award_content .tab-pane.active").remove();
                $("#award_content .tab-pane:last").addClass('active');
            }
        }else{
            alert('抱歉无法删除，奖项至少保留一个');
        }
    }
</script>